package cm.xiqi.cms.oper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.xiqi.cms.beans.UserBean;
import cn.xiqi.cms.hibernate.DAO.UsrDAOImpl;
import cn.xiqi.cms.hibernate.beans.Usrinfo;
import cn.xiqi.cms.hibernate.service.UsrService;
import cn.xiqi.cms.hibernate.service.UsrServiceImpl;

public class UserOper {
	private UsrService service;
	
	public UserOper(){
		service = new UsrServiceImpl();
		service.setDao(new UsrDAOImpl());
	}
	
	@SuppressWarnings("rawtypes")
	public Map<String, Object> getAll(int page, int size){
		List<Usrinfo> records;
		List datas;
		Map<String, Object> map = new HashMap<>();
		int count;
		records = service.getAll(page, size);
		count = service.getCount("all");
		datas = toMap(records);
		map.put("total", count);
		map.put("rows", datas);
		return map;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private List toMap(List<Usrinfo> records){
		List datas = new ArrayList<>();
		
		for(Usrinfo record:records){
//			Map<String, Object> data = new HashMap<>();
//			data.put("userid", record.getUsrID());
//			data.put("name", record.getName());
//			data.put("depart", record.getDepart());
			UserBean data = new UserBean(record);
			datas.add(data);
		}
		return datas;
	}
}
